package cn.dujc.superkid.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.MyClassResult;

public class MyCourseAdapterRight extends RecyclerView.Adapter<MyCourseAdapterRight.MyViewHolder> {
    private final String  TAG  = MyCourseAdapter.class.getName();
    private Context mContext;
    private List<MyClassResult.MyClass> list;

    public MyCourseAdapterRight(List<MyClassResult.MyClass> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_course, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
    }

    @Override
    public int getItemCount() {
        Log.i(TAG,"==============caizhijia======MyCoursAdapter=====" +list.size());
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private View mView;
        private TextView lessonname;
        private TextView item_tv_couse_info;
        private ImageView item_iv_couse_image;
//        TextView resolvtion;
//        TextView continu;

        public MyViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
            item_iv_couse_image = itemView.findViewById(R.id.item_iv_couse_image);
            lessonname = itemView.findViewById(R.id.item_tv_couse_title);
            item_tv_couse_info = itemView.findViewById(R.id.item_tv_couse_info);
//            resolvtion = itemView.findViewById(R.id.error_resolvtion);
//            continu = itemView.findViewById(R.id.error_continu);

        }
    }

    public Bitmap getImageBitmap(String url) {
        URL imgUrl = null;
        Bitmap bitmap = null;
        try {
            imgUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) imgUrl
                    .openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);
            is.close();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }
}
